package com.study.utils;

import cn.hutool.core.util.ObjectUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
public class LoginIntercept implements HandlerInterceptor {



    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)  {
        if(ObjectUtil.isNull(UserHolder.getUser())){
            //如果用户信息为空则拦截
            log.debug("被拦截路径：{}",request.getServletPath());
            response.setStatus(401);
            return false;
        }
        //否则放行
        return true;
    }

}
